﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using SDF.Models;

namespace SDF.MvcApp.Areas.Backend.Controllers
{
    public class ControllerBase : Controller
    {
        public SqlServerDB db = new SqlServerDB();


        //"statusCode":"200", 
        //"message":"操作成功", 
        //"navTabId":"", 
        //"rel":"", 
        //"callbackType":"closeCurrent",
        //"forwardUrl":""


        public ActionResult Success()
        {
            return Msg("200", "操作成功", "", "", "closeCurrent", "");
        }

        public ActionResult Success(string navTabId)
        {
            return Msg("200", "操作成功", navTabId, "", "closeCurrent", "");
        }

        public ActionResult Forward(string forwardUrl, string navTabId)
        {
            return Msg("200", "操作成功", navTabId, "", "forward", forwardUrl);
        }

        public ActionResult NavTabId(string navTabId)
        {
            return NavTabId(navTabId, true);
        }

        public ActionResult NavTabId(string navTabId, bool closeCurrent)
        {
            string closeCurrentStr = closeCurrent ? "closeCurrent" : "";
            return Msg("200", "操作成功", navTabId, "", closeCurrentStr, "");
        }


        public ActionResult Error()
        {
            return Msg("300", "操作失败", "", "", "", "");
        }

        public ActionResult Msg(string statusCode, string message, string navTabId, string rel, string callbackType, string forwardUrl)
        {
            Hashtable ht = new Hashtable();
            ht.Add("statusCode", statusCode);
            ht.Add("message", message);
            ht.Add("navTabId", navTabId);
            ht.Add("rel", rel);
            ht.Add("callbackType", callbackType);
            ht.Add("forwardUrl", forwardUrl);

            return Json(ht);
        }

    }
}
